package com.qingfeng.medical.controller.front.hosp;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.qingfeng.medical.base.controller.BaseController;
import com.qingfeng.medical.base.log.annotation.Log;
import com.qingfeng.medical.base.log.enums.BusinessType;
import com.qingfeng.medical.base.result.Result;
import com.qingfeng.medical.biz.hosp.domain.vo.DepScheduleVo;
import com.qingfeng.medical.biz.hosp.domain.vo.ScheduleVo;
import com.qingfeng.medical.biz.hosp.domain.vo.ScheduleWeekDayVo;
import com.qingfeng.medical.biz.hosp.service.ScheduleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;
import java.util.Date;
import java.util.List;


/**
 * 排班管理
 *
 * @author 清风学Java
 * @date 2023-04-14 14:47:17
 */
@Api(tags = "排班管理管理")
@RestController
@RequestMapping("/api/hosp/schedule")
@Validated
public class ScheduleApiController extends BaseController {

    @Autowired
    private ScheduleService scheduleService;

    @ApiOperation(value = "根据科室门诊Id，分页查询排班列表", notes = "根据科室门诊Id，分页查询排班列表")
    @GetMapping("/dep/weekday")
    @Log(title = "前台排班管理", businessType = BusinessType.SELECT, message = "根据科室门诊Id，分页查询排班列表")
    public Result<ScheduleWeekDayVo> scheduleWeekdayList(
            @ApiParam(name = "page", value = "当前页码", required = true)
            @RequestParam("page") @NotNull(message = "页码不能为空") Long page,
            @ApiParam(name = "limit", value = "每页记录数", required = true)
            @RequestParam("limit") @NotNull(message = "每页条目数不能为空") Long limit,
            @ApiParam(name = "depId", value = "科室门诊Id", required = true)
            @RequestParam("depId") @NotNull(message = "科室门诊Id不能为空") Long depId) {
        return Result.ok(scheduleService.scheduleWeekDay(page, limit, depId));
    }

    @ApiOperation(value = "排班管理列表", notes = "排班管理列表")
    @GetMapping("/list")
    @Log(title = "前台排班管理", businessType = BusinessType.SELECT, message = "排班管理列表")
    public Result<List<ScheduleVo>> scheduleList(
            @ApiParam(name = "weekDay", value = "排班日期", required = true)
            @DateTimeFormat(pattern = "yyyy-MM-dd")
            @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
            @RequestParam("weekDay") Date weekDay,
            @ApiParam(name = "depId", value = "科室门诊Id", required = true)
            @RequestParam("depId") Long depId) {
        List<ScheduleVo> scheduleVo = scheduleService.findScheduleVo(weekDay, depId);
        return Result.ok(scheduleVo);
    }

    @ApiOperation(value = "根据Id查询排班挂号信息", notes = "根据Id查询排班挂号信息")
    @GetMapping("/dep/info/{id}")
    @Log(title = "前台排班管理", businessType = BusinessType.SELECT, message = "根据Id查询排班挂号信息")
    public Result<DepScheduleVo> depScheduleInfo(@PathVariable("id") Long id){
        DepScheduleVo depScheduleVo = scheduleService.depScheduleInfo(id);
        return Result.ok(depScheduleVo);
    }
}
